import { all, fork, put, takeLatest } from 'redux-saga/effects';
import { LoadDesignsParams } from 'src/modules';
import { ActionWithPayload } from '../types';
import { Actions } from './actions';
import { ActionType } from './types';

function* loadDesigns(action: ActionWithPayload<ActionType.LoadDesigns, LoadDesignsParams>): Generator {
  try {
    const payload = [
      { id: '1', name: 'hahDesign' },
      { id: '2', name: 'designName' },
    ];
    console.log(action);

    yield put(Actions.loadDesignsDone(payload));
  } catch (error) {}
}

function* watchCanvasTaskSagas(): Generator {
  yield takeLatest(ActionType.LoadDesigns, loadDesigns);
}

export default function* canvasSaga(): Generator {
  yield all([fork(watchCanvasTaskSagas)]);
}
